<?php
class Controller_Admin_Setting extends Controller_Admin_Layout
{
    /**
     * Show the main page
     */
    public function action_index()
    {
        // Get all settings
        if($this->request->method() === 'POST')
        {
            $post = Arr::extract($_POST, array('setting'));
            foreach($post['setting'] as $id => $row)
            {
                $obj = ConfigurationTable::getInstance()->find($id);
                foreach ($row as $key => $value)
                {
                    $obj->key = $key;
                    $obj->value = $value;
                }
                $obj->save();
            }
        }
        
        $settings = Doctrine_Query::create()->from('Configuration c')
                ->execute();
        $this->template->main = View::factory('admin/setting', array(
            'settings' => $settings
        ));
    }
}